<template>
	<view class="user">
		<view class="header">
			<view class="user-info">
				<image :src="staffInfo.avatar" mode="aspectFill"></image>
				<text>{{staffInfo.staff_name}}</text>
			</view>
			
			<view class="time">
				<view class=""></view>
				<view class="tab">
					<view class="li" @click="onTypeClick('month')" :class="type == 'month' ? 'on' : ''">
						<text>本月</text>
					</view>
					<view class="li" @click="onTypeClick('all')" :class="type == 'all' ? 'on' : ''">
						<text>本年</text>
					</view>
				</view>
			</view>
			
			
			<view class="statistics">
				<view class="li">
					<text>{{statisticsData.pendingWriteOffCount||0}}</text>
					<text>待核销</text>
				</view>
				
				<view class="li">
					<text>{{statisticsData.cardReservationCount||0}}</text>
					<text>次卡预约</text>
				</view>
			</view>
		</view>
		
		<view class="tool-main">
			<view class="title">
				<text>快捷工具</text>
			</view>
			<view class="tool">
				<view class="li" @click="onJump('/pages/staff/scan_code')">
					<image :src="baseUrl + '/static/wximages/staff/staff-icon-01.png'" mode="widthFix"></image>
					<text>次卡核销</text>
				</view>
				<view class="li" @click="onJump('/pages/reserve/project/record?type=staff')">
					<image :src="baseUrl + '/static/wximages/staff/staff-icon-02.png'" mode="widthFix"></image>
					<text>核销记录</text>
				</view>
				<view class="li" @click="onJump('/pages/reserve/card/record?type=staff')">
					<image :src="baseUrl + '/static/wximages/staff/staff-icon-04.png'" mode="widthFix"></image>
					<text>预约列表</text>
				</view>
				<view class="li" @click="onJump('/pages/admin/order/index')">
					<image :src="baseUrl + '/static/wximages/staff/staff-icon-03.png'" mode="widthFix"></image>
					<text>订单列表</text>
				</view>
				<view class="li" @click="onJump('/pages/extension/news_list/index?type=1')">
					<image :src="baseUrl + '/static/wximages/staff/staff-icon-05.png'" mode="widthFix"></image>
					<text>通知公告</text>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statisticsData: {},
				staffInfo: {},
				baseUrl: this.$baseUrl,
				
				type: 'month'
			}
		},
		onShow() {
			this.statistics()
			this.getStaffUserInfo();
		},
		methods: {
			onJump(url) {
				uni.navigateTo({
					url: url
				})
			},
			onTypeClick(type) {
				this.type = type;
				this.statistics()
			},
			statistics() {
				uni.request({
					url: this.baseUrl + '/api/staff/statistics',
					method: 'GET',
					header: {
						token: uni.getStorageSync('stafftoken')
					},
					data: {
						type: this.type
					},
					success: (res) => {
						if (res.data.status == 200) {
							if (res.data.data) {
								this.statisticsData = res.data.data;
							}
						}
					}
				})
			},
			
			getStaffUserInfo() {
				uni.request({
					url: this.baseUrl + '/api/staff/infos',
					method: 'GET',
					header: {
						token: uni.getStorageSync('stafftoken')
					},
					success: (res) => {
						console.log('res',res.data.status);
						if (res.data.status == 200) {
							if (res.data.data) {
								this.staffInfo = res.data.data;
							}
						} else {
							uni.navigateTo({
								url: '/pages/staff/login'
							})
						}
					}
				})
			},
		}
	}
</script>
<style>
	page {
		background: #fff;
	}
</style>
<style scoped lang="scss">
	.header {
		padding: 30rpx;
		background-color: #fff;
		border-bottom: 20rpx solid #f3f3f3;
		.user-info {
			display: flex;
			align-items: center;
			image {
				width: 88rpx;
				height: 88rpx;
			 	border: 2rpx solid #fff;
				border-radius: 50%;
				// border-image: linear-gradient(309deg, rgba(57.00000040233135, 145.00000655651093, 125.00000014901161, 1), rgba(255, 255, 255, 0.23000000417232513)) 2 2;
			}
			text {
				font-size: 32rpx;
				color: #050505;
				margin-left: 26rpx;
			}
		}
		
		.time {
			display: flex;
			align-items: center;
			justify-content: space-between;
			.tab {
				display: flex;
				align-items: center;
				.li {
					width: 112rpx;
					line-height: 48rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 0rpx 0rpx 0rpx 0rpx;
					border: 1rpx solid #003153;
					color: #003153;
					&.on {
						background: #003153;
						color: #fff;
					}
				}
			}
		}
		
		.statistics {
			padding: 20rpx;
			display: flex;
			align-items: center;
			.li {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				margin-right: 40rpx;
				text {
					&:nth-child(1){
						font-size: 39rpx;
						color: #003153;
					}
					&:nth-child(2) {
						font-size: 26rpx;
						color: #9797A1;
						margin-top: 23rpx;
					}
				}
			}
		}
	}
	.tool-main {
		padding: 30rpx;
		.title {
			font-weight: 500;
			font-size: 32rpx;
			padding: 10rpx 0;
			color: #121836;
		}
		.tool {
			background-color: #fff;
			display: flex;
			flex-wrap: wrap;
			padding: 30rpx;
			.li {
				width: 118.5rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				margin-right: 52rpx;
				margin-bottom: 52rpx;
				&:nth-child(4n+4) {
					margin-right: 0;
				}
				image {
					width: 62rpx;
					height: 62rpx;
					border-radius: 50%;
				}
				text {
					font-size: 25rpx;
					color: #3D3D3D;
					margin-top: 8rpx;
				}
			}
		}
	}
	
</style>